﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Emgu.CV.Structure;
using Emgu.CV;
using System.Drawing;
using AsyncCamera.Camera.media;

namespace AsyncCamera.Camera.medua.filters
{
    class TextFilter: MediaFilter
    {
        private Guid sourceId;

        public TextFilter(MediaSource source): base()
        {
            sourceId = source.GUID;
            plugIn[sourceId] = source;
            lastFrame[sourceId] = source.Frame;
            if (source.Frame != null)
            {
                Tick(null, null);
            }
            else
            {
                frame = null;
            }
        }

        protected override void Tick(object sender, EventArgs e)
        {
            Frame newFrame = plugIn[sourceId].Frame;
            if (newFrame != null && (lastFrame[sourceId] == null || lastFrame[sourceId].Id != newFrame.Id))
            {
                lastFrame[sourceId] = newFrame.Clone();
                Image<Bgr, Byte> img = lastFrame[sourceId].Image as Emgu.CV.Image<Bgr, Byte>;
                MCvFont f = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0);
                img.Draw("HAHA", ref f, new Point(10, 80), new Bgr(0, 255, 0));
                frame = lastFrame[sourceId];
            }
        }
    }
}
